//
//  Channel.swift
//  NetEasyNew
//
//  Created by 蔡万鸿 on 15/6/6.
//  Copyright (c) 2015年 黄花菜. All rights reserved.
//

import UIKit

class Channel: NSObject {
   
    /**
    *  频道名称
    */
    var tname: String?
    /**
    *  频道代号
    */
    var tid: String? {
        didSet {
            self.urlString = "\(tid!)" + "/0-20.html"
        }
    }
    /**
    *  新闻地址
    */
    var urlString: String?
    
    /**
    *  返回频道的数组
    */
    class func ChannelList() -> [Channel] {
    
        let url = NSBundle.mainBundle().URLForResource("topic_news.json", withExtension: nil)
        
        let data = NSData(contentsOfURL: url!)

        var json:AnyObject = NSJSONSerialization.JSONObjectWithData(data!,options:NSJSONReadingOptions.AllowFragments,error:nil)!

        var array = (json as! NSDictionary)["tList"] as! [[String: AnyObject]]
        
        var arrayM: [Channel] = [Channel]()
        
        for dict in array {
            
            var cc = Channel()
        
            cc.tname = dict["tname"] as? String
            cc.tid = dict["tid"] as? String
        
            arrayM.append(cc)
        }

        return arrayM
    }
    
    // 重写对象的描述信息 - 建议重要的模型类，最好添加一个，方便调试
    override var description: String {
        
        let properties = ["tname","tid"]
        
        return "\(dictionaryWithValuesForKeys(properties))"
    }
}
